/* 
 * File:   MPLSH.h
 * Author: liuyi
 *
 * Created on September 10, 2009, 9:47 PM
 */

#ifndef _MPLSH_H
#define	_MPLSH_H

#include "Toolkit.h"
#include "SampleSpace.h"

using namespace std;

class Sample;
class HashModel;

// refer to paper: Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search
class MPLSH {
public:
    void assignParam(int M, int L, float **a, float **b, float W);

    void insert(Sample *sample);

    void insert(vector<Sample *> &sampleList);

    void store2File(const char *modelPath);

    static MPLSH * loadFromFile(const char *modelPath) throw(FileNotFoundException);

    void retrieveNeighbors(vector<Sample *> &neighbors, const Sample &sample);

    SampleSpace & getSampleSpace() {
        return *m_sampleSpace;
    }

    MPLSH(SampleSpace &sampleSpace, bool copySample) {
        m_sampleSpace = new SampleSpace(sampleSpace.getDimension(), sampleSpace.getDistance()->getDistanceType());

        m_copySample = copySample;
        m_hashModel = NULL;
    }

    ~MPLSH();

private:
    SampleSpace *m_sampleSpace;

    bool m_copySample;

    vector<Sample *> m_sampleList;

    HashModel *m_hashModel;

    void releaseModel();

    MPLSH();
    MPLSH(const MPLSH &);

};

#endif	/* _MPLSH_H */

